package com.mayikt.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mayikt.edu.domain.UserLoginLog;
import com.mayikt.edu.mapper.UserLoginLogMapper;
import com.mayikt.edu.service.UserLoginLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 登录日志表(UserLoginLog)表服务实现类
 *
 * @author wangjin
 * @since 2023-11-02 10:49:05
 */
@Slf4j
@Async("newSaskExecutor")
@Service("userLoginLogService")
public class UserLoginLogServiceImpl extends ServiceImpl<UserLoginLogMapper, UserLoginLog> implements UserLoginLogService {
    @Resource
    private UserLoginLogMapper userLoginLogMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UserLoginLog queryById(Long id) {
        return this.userLoginLogMapper.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param userLoginLog 筛选条件
     * @return 查询结果
     */
    @Override
    public List<UserLoginLog> queryByPage(UserLoginLog userLoginLog) {
        return this.userLoginLogMapper.selectList(getQuery(userLoginLog));
    }

    private QueryWrapper getQuery(UserLoginLog userLoginLog) {
        QueryWrapper queryWrapper = new QueryWrapper();

        return queryWrapper;
    }

    /**
     * 新增数据
     *
     * @param userLoginLog 实例对象
     * @return 实例对象
     */
    @Override
    public UserLoginLog insert(UserLoginLog userLoginLog) {
        log.info("[2 正在开始记录日志]");
        this.userLoginLogMapper.insert(userLoginLog);
        return userLoginLog;
    }

    /**
     * 修改数据
     *
     * @param userLoginLog 实例对象
     * @return 实例对象
     */
    @Override
    public UserLoginLog update(UserLoginLog userLoginLog) {
        this.userLoginLogMapper.updateById(userLoginLog);
        return this.queryById(userLoginLog.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.userLoginLogMapper.deleteById(id) > 0;
    }
}
